from interface.MemberInterface import MemberInterface
from utils.SendMethod import SendMethod


class CartInterface:
    def __init__(self, url):
        self.url = url

    # 添加购物车
    def add_cart(self, login_payload, payload):
        # 获取token
        token = MemberInterface(self.url).get_member_token(login_payload)
        # 发送添加购物车请求,获得响应数据
        url = self.url + '/cart/add'
        return SendMethod.send_method('post', url=url, headers=token, json=payload)


if __name__ == '__main__':
    url = 'http://47.108.206.100:8085'
    login_payload = {
        'username': 'yyn1234',
        'password': '12345678'
    }
    payload = {
        "createDate": "2022-07-23T02:51:56.128Z",
        "deleteStatus": 0,
        "id": 0,
        "memberId": 1807,
        "memberNickname": "yangyu",
        "modifyDate": "2022-07-23T02:51:56.128Z",
        "price": 5499,
        "productAttr": '[{"key":"颜色","value":"金色"},{"key":"容量","value":"32G"}]',
        "productBrand": "苹果",
        "productCategoryId": 19,
        "productId": 29,
        "productName": "Apple iPhone 8 Plus 64GB 红色特别版 移动联通电信4G手机",
        "productPic": "http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/images/20180615/5acc5248N6a5f81cd.jpg",
        "productSkuCode": "201808270027001",
        "productSkuId": 106,
        "productSn": "7437799",
        "productSubTitle": " 【限时限量抢购】Apple产品年中狂欢节，好物尽享，美在智慧！速来 >> 勾选[保障服务][原厂保2年]，获得AppleCare+全方位服务计划，原厂延保售后无忧。",
        "quantity": 1
    }
    print(CartInterface(url).add_cart(login_payload, payload))
